<?php
namespace app\api\controller;

use app\api\common\controller\Api;
use hg\apidoc\annotation as Apidoc;
use think\facade\Db;
use app\admin\model\PlatformSpec;

use Endroid\QrCode\QrCode;
/**
 * @Apidoc\Title("Demo.php")
 * @Apidoc\Group("api")
 */
class Data extends Api
{
    /**
     * 无需登录的方法,同时也就不需要鉴权了
     * @var array
     */
    protected $noNeedLogin = ['*'];
    public function __construct()
    {
        
       
    }
    /**
     * 无需鉴权的方法,但需要登录
     * @var array
     */
    protected $noNeedRight = [];
    public function aa(){
    $qrCode = new QrCode('5345');
     header('Content-Type: '.$qrCode->getContentType());
     // echo $qrCode->writeString();die;
     $img=$qrCode->writeDataUri();
     echo $img;
     // $file_name="upload/20220712/100.png";
      // $qrCode->writeFile($file_name);
    }
    public function h(){
            $result['year'] = date('Y');//年
            $result['month'] = date('m');//月
            $result['day'] = date('t'); //31//月总天数
            $result['w'] = date('w');//
            $result['j'] = date('j');
            $result['firstDay'] = date('w', mktime(0, 0, 0, $result['month'], 1, $result['year']));
            dd($result);
    }
      public static function day_report($params = [])
    {   
        $params['month']='';
        $month = $params['month'];
        if (empty($month))
        {
            $month = date('Y-m');
        }

        $month_begin = strtotime($month . '-01');
        $month_end =  strtotime("+1 months", $month_begin) - 24*3600;
        
        $dt_begin = $month_begin - (date('N', $month_begin)-1) * 24*3600;
        $dt_end = $month_end + (7 - date('N', $month_end)) * 24*3600;

        $today = strtotime(date('Y-m-d'));

        $list = [];
        $dt = $dt_begin;
        $aaa=[];
        while ($dt <= $dt_end)
        {
            $class = '';
            if ($dt < $month_begin || $dt > $month_end)
            {
                $class .= ' other';
            }
            if ($dt == $today)
            {
                $class .= ' today';
            }
            if ($dt > $today)
            {
                $class .= ' future';
            }
           
            $list[] = [
                'dt'  => date('Y-m-d', $dt),
                'day' => date('j', $dt),
                'class' => $class,
            ];
            
            $dt += 24*3600;
        }
        // for ($i=0; $i <30 ; $i++) { 
        //     $aaa[]=[
        //         'create_time'=>mktime(0,0,0,date("m"),date("d")+$i,date("Y")),
        //         'tree_ticket_id'=>2,
        //         'price'=>35
        //     ];
        // }
        // Db::name('ticket_price')->insertAll($aaa);
        // dump($aaa);
        $list = array_chunk($list, 7);

        // 月份选择
        $month_val = strtotime($month . '-01');
        $month_cur = date('Y年m月', $month_val);
        $month_pre = date('Y-m', strtotime("-1 months", $month_val));
        $month_next = '';

        if ($month != date('Y-m'))
        {
            $month_next = date('Y-m', strtotime("+1 months", $month_val));
        }
        if($month == date('Y-m'))$month_next = date('Y-m', strtotime("+1 months", $month_val));
        $data = [
            'month' => $month,
            'list' => $list,
            'month_cur' => $month_cur,
            'month_pre' => $month_pre,
            'month_next' => $month_next,
        ];
        dd($data);
        return self::_success($data);
    }

    public function pr(){
        $tree_ticket_id=6;
        $data=Db::name('ticket_price')->where('tree_ticket_id',$tree_ticket_id)->whereTime('create_time', '>=', 1680105600)->fetchsql(false)->select()->toArray();
        // dd($data);
        foreach ($data as $k => $v) {
                $dayOfWeek = date('N', $v['create_time']);
                $year = date('Y', $v['create_time']);
                $holiday = array(
                    date('Y-m-d', strtotime("$year-01-01")), //元旦
                    date('Y-m-d', strtotime("$year-04-05")), //清明节
                    date('Y-m-d', strtotime("$year-04-29")), //劳动节
                    date('Y-m-d', strtotime("$year-04-30")), //劳动节
                    date('Y-m-d', strtotime("$year-05-01")), //劳动节
                    date('Y-m-d', strtotime("$year-05-02")), //劳动节
                    date('Y-m-d', strtotime("$year-05-03")), //劳动节
                    date('Y-m-d', strtotime("$year-06-01")), //儿童节
                    date('Y-m-d', strtotime("$year-10-01")), //国庆节
                    date('Y-m-d', strtotime("$year-10-02")), //国庆节
                    date('Y-m-d', strtotime("$year-10-03")), //国庆节
                    date('Y-m-d', strtotime("$year-10-04")), //国庆节
                    date('Y-m-d', strtotime("$year-10-05")), //国庆节
                    date('Y-m-d', strtotime("$year-10-06")), //国庆节
                    date('Y-m-d', strtotime("$year-10-07")), //国庆节
                );
            //     $price=14;
            // if ($dayOfWeek == 6 || $dayOfWeek == 7 || in_array(date('Y-m-d',$v['create_time']), $holiday)) {
            //     $price=19;
            // }
             Db::name('ticket_price')->where('id',$v['id'])->update(['price'=>498,'activity_price'=>298]);
        }
        dd($data);
    }
}
